<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			// #ifdef APP-PLUS
			var pinf = plus.push.getClientInfo();
			console.log(pinf)
			var cid = pinf.clientid; //客户端标识
			console.log('cid：' + cid);

			//开启推送
			uni.subscribePush({
				provider: "unipush",
				success: function(res) {
					console.log("success:" + JSON.stringify(res))
				}
			});
			let osname = plus.os.name
			console.log(osname)
			if (osname == 'Android') {
				uni.onPush({
					provider: "unipush",
					success: function() {
						console.log("监听透传成功");
					},
					callback: function(data) {
						console.log("接收到透传数据：" + JSON.stringify(data));
						plus.push.createMessage(data.data, {});
					}
				});
			}
			// 监听在线消息事件
			if (osname == 'iOS') {
				plus.push.addEventListener('receive', function(msg) {
					plus.push.createMessage(msg.content, "LocalMSG", {
						cover: false
					});
					setTimeout(() => {
						plus.push.clear();
					}, 3000)
				}, false);
			}
			plus.push.addEventListener(
				"click",
				//这里写业务逻辑
				function(data) {
					console.log(data);
				},
				false
			);
			plus.push.addEventListener('receive', function(res) {
				let options = {
					cover: false
				};
				console.log(res)
				console.log(res.content)
				plus.push.createMessage(res.content, res.payload, options);
			}, false)

			var token = uni.getStorageSync('token')
			// if(!token) return
			// this.request({
			// 	url: '/czb/User/updateUserClientId',
			// 	method: 'POST',
			// 	data: {
			// 		'token':token,
			// 		'client_id': cid
			// 	},
			// }).then((ret) => {
			// 	console.log(ret);
			// 	// if (ret.code == 0) {
			// 	// 	this.content = ret.data.content
			// 	// }
			// })
			// plus.push.addEventListener('click', function(msg) {
			// 	console.log("msg", msg);
			// 	//处理点击消息的业务逻辑代码 
			// 	plus.nativeUI.alert("click:" + JSON.stringify(msg));
			// 	plus.nativeUI.alert(msg.payload);
			// 	// 被点击时跳转应用首页
			// 	uni.navigateTo({
			// 		url: './pages/index/index',
			// 	})
			// }, false);
			// //监听接收透传消息事件  
			// plus.push.addEventListener('receive', function(msg) {
			// 	//处理透传消息的业务逻辑代码 
			// 	alert('谈不谈就完了')
			// 	plus.nativeUI.alert("recevice:" + JSON.stringify(msg.title))
			// 	plus.nativeUI.alert("recevice:" + JSON.stringify(msg.payload))
			// 	// plus.push.createMessage( content, payload, option );
			// 	// 创建手机通知栏消息
			// 	plus.push.createMessage(msg.title, msg.payload);
			// }, false);
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	page {
		background: #f7f8fc;
		height: 100%;
	}

	.fl {
		float: left;
	}

	.fr {
		float: right;
	}

	.flex {
		display: flex;
	}

	.flex-row-ac {
		display: flex;
		align-items: center;
	}

	.flex-col-ac {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.flex-col {
		display: flex;
		flex-direction: column;
	}

	.flex-c {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.flex-bc {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.flex-ac {
		display: flex;
		justify-content: space-around;
		align-items: center;
	}

	.ellipsis {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
	}
</style>
